package www.openteam.com.adapter.PrdctnMngmnt;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.SendRcvBean;
import www.openteam.com.rewrite.MListView;
import www.openteam.com.rewrite.MTextView;

/**
 * Created by OT on 2017-10-20.
 */

public class SendRcvAdapter extends RecyclerView.Adapter<SendRcvAdapter.ViewHodler> {
    Context context;
    List<SendRcvBean.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    @Bind(R.id.tv_id)
    MTextView tvId;
    @Bind(R.id.SendRcv_client_rson)
    MTextView SendRcvClientRson;
    @Bind(R.id.SendRcv_client_name)
    MTextView SendRcvClientName;
    @Bind(R.id.SendRcv_pro_name)
    MTextView SendRcvProName;
    @Bind(R.id.SendRcv_part)
    TextView SendRcvPart;
    @Bind(R.id.SendRcv_unit)
    TextView SendRcvUnit;
    @Bind(R.id.SendRcv_produce)
    TextView SendRcvProduce;
    @Bind(R.id.SendRcv_sendoutnum)
    TextView SendRcvSendoutnum;
    int i =1;
    private boolean isChecked;
    public OnLongClickListener onLongClickListener;


    public interface OnLongClickListener{
        void longClick(int postion);
    }

    public void setOnLongClickListener(OnLongClickListener onLongClickListener) {
        this.onLongClickListener = onLongClickListener;
    }

    public SendRcvAdapter(Context context, List<SendRcvBean.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public ViewHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHodler(LayoutInflater.from(context).
                inflate(R.layout.item_sendrecv, parent, false));
    }

    @Override
    public void onViewAttachedToWindow(ViewHodler holder) {
        super.onViewAttachedToWindow(holder);
    }

    @Override
    public void onBindViewHolder(ViewHodler holder, final int position) {
        SendRcvBean.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.tvId.setText(""+position);//客户名称
        holder.SendRcvClientName.setText(dataBean.getCustname());//工程单号
        holder.SendRcvClientRson.setText(dataBean.getProcno());//客户单号
        holder.SendRcvClientName.setText(dataBean.getProdcode());//产品编号
        holder.SendRcvProName.setText(dataBean.getName());//产品名称
        holder.SendRcvSendoutnum.setText(dataBean.getOnumb());//发外数量
        holder.SendRcvProduce.setText(dataBean.getAprocedure()+ "");//工序
        holder.SendRcvAnmen.setText(dataBean.getAname());//工序名称
        holder.SendRcvUnit.setText(dataBean.getPartID());//部件
        holder.SendRcvPart.setText(dataBean.getGroupname());//配件
        if (isChecked){
            holder.SendRcvParent.setBackgroundColor(context.getResources().getColor(R.color.red_shallow));
        }else{
            holder.SendRcvParent.setBackgroundColor(context.getResources().getColor(R.color.green));
        }
        holder.SendRcvParent.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (onLongClickListener!=null){
                    onLongClickListener.longClick(position);
                }
                return false;
            }
        });

    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }

    public class ViewHodler extends RecyclerView.ViewHolder {

        @Bind(R.id.tv_id)
        MTextView tvId;
        @Bind(R.id.SendRcv_client_rson)
        MTextView SendRcvClientRson;
        @Bind(R.id.SendRcv_client_name)
        MTextView SendRcvClientName;
        @Bind(R.id.SendRcv_pro_name)
        MTextView SendRcvProName;
        @Bind(R.id.SendRcv_part)
        TextView SendRcvPart;
        @Bind(R.id.SendRcv_unit)
        TextView SendRcvUnit;
        @Bind(R.id.SendRcv_produce)
        TextView SendRcvProduce;
        @Bind(R.id.SendRcv_sendoutnum)
        TextView SendRcvSendoutnum;
        @Bind(R.id.SendRcv_aname)
        TextView SendRcvAnmen;
        @Bind(R.id.SendRcv_parent)
        LinearLayout SendRcvParent;
        @Bind(R.id.SendRcv_cardview)
        CardView cardView;

        public ViewHodler(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
